
package com.yimixian.app.user;

import com.yimixian.app.R;
import com.yimixian.app.activity.BaseNaviFragmentGroupActivity;
import com.yimixian.app.common.Constants;
import com.yimixian.app.data.DataManager;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;

public class SettingsActivity extends BaseNaviFragmentGroupActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_activity);
        setTopNavi(R.drawable.ic_back_selector,
                "", getString(R.string.setting),
                null, null);
    }


    @Override
    protected void initPrimaryFragment() {
        switchPrimaryFragment(0);
    }

    @Override
    protected Class<? extends Fragment> getPrimaryFragmentClass(int fragmentId) {
        return SettingFragment.class;
    }


    @Override
    protected int getPrimaryFragmentStubId(int fragmentId) {
        return R.id.content_frame;
    }

    protected void onDestroy() {
        super.onDestroy();
        SharedPreferences mSharedPreferences = getSharedPreferences(
                Constants.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
        DataManager.getInstance().onMainActivityDestroy(mSharedPreferences);
    }

//    private DataManager mDataManager;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//        mDataManager = DataManager.getInstance();
//
//        setContentView(R.layout.settings_activity);
//        ButterKnife.inject(this);
//
//        String versionName = mDataManager.get(CacheKeys.VERSION_NAME);
//        Integer versionCode = mDataManager.get(CacheKeys.VERSION_CODE);
//        mVersionCodeTextView.setText("版本号：" + versionName + "(" + versionCode + ")");
//        mQuitButton.setVisibility(isLogin() ? View.VISIBLE : View.GONE);
//        mQuitButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                MobclickAgent.onEvent(SettingsActivity.this, StatConstants.SETTING_QUIT_CLICK);
//                mDataManager.remove(CacheKeys.TOKEN);
//                CartManager.getInstance().mTotalQuantity = 0;
//                CartManager.getInstance().clearCart();
//
//                SharedPreferencesHelper.clearAddress(SharePreferenceKeys.ADDRESSES);
//                SharedPreferencesHelper.clearAddress(SharePreferenceKeys.CURRENT_ADDRESS);
//
//                mDataManager.remove(CacheKeys.CURRENT_STORE);
//                mDataManager.remove(CacheKeys.CURRENT_USER);
//                mDataManager.remove(CacheKeys.ORDERS);
//                setResult(RESULT_OK);
//                EventBus.getDefault().post(new ShowAdSelectChange());
//                finish();
//            }
//        });
//        mServiceButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                AppConfig appConfig = mDataManager.get(CacheKeys.APP_CONFIG);
//                if (appConfig == null || StringUtils.isEmpty(appConfig.serviceTermsUrl)) return;
//                Intent intent = new Intent(SettingsActivity.this, WebViewActivity.class);
//                intent.putExtra(WebViewActivity.EXTRA_TITLE, getResources().getString(R.string.setting_service));
//                intent.putExtra(WebViewActivity.EXTRA_URL, appConfig.serviceTermsUrl);
//                startActivity(intent);
//            }
//        });
//    }
//
//    /** 判断是否登录 */
//    public boolean isLogin() {
//        if (DataManager.getInstance().get(CacheKeys.TOKEN) == null) {
//            return false;
//        }
//        return true;
//    }
//    @Override
//    protected String getTitleBarText() {
//        return getString(R.string.setting);
//    }
}
